<?php

class DareDAO extends DAO {

    public static function getdaresbypost($uid = 0)
	{
		$uid = intval($uid);
        if (!$uid) return false;
        
        $dbconf = self::dbhash($uid, "pvn_global", "dare");
        $dbconn = self::getconn($uid, $dbconf, __FUNCTION__);
        if (!$dbconn) return false;
        
        $sql = "select * from {$dbconf[4]} where uid={$uid}";
        $ret = self::dbquery($dbconn, $sql, "rows");
        self::dbclose($dbconn);
        if ($ret === false) return false;
        
        return $ret;
	}

	public static function getdaresbytarget($uid = 0)
	{
		$uid = intval($uid);
        if (!$uid) return false;
        
        $dbconf = self::dbhash($uid, "pvn_global", "dare");
        $dbconn = self::getconn($uid, $dbconf, __FUNCTION__);
        if (!$dbconn) return false;
        
        $sql = "select * from {$dbconf[4]} where tuid={$uid}";
        $ret = self::dbquery($dbconn, $sql, "rows");
        self::dbclose($dbconn);
        if ($ret === false) return false;
        
        return $ret;
	}

	public static function setdare($uid = 0, $tuid = 0, $data = array())
	{
		$uid = intval($uid);
		$tuid = intval($tuid);
		if (!$uid || !$tuid || !$data || !is_array($data)) return false;
    
        $sets = array();
		foreach($data as $k => $v)
		{
			switch($k)
			{
				case 'price':
				case 'gb':
				case 'ctm':
				case 'auid':
				case 'actm':
				case 'acount':
					$v = intval($v);
					$sets[] = "{$k}='{$v}'";
					break;
			}
		}
		if(!$sets) return false;
		$sets = implode(",", $sets);
        
		$dbconf = self::dbhash($uid, "pvn_global", "dare");
		$dbconn = self::getconn($uid, $dbconf, __FUNCTION__);
		if (!$dbconn) return false;
		
		$sql = "update {$dbconf[4]} set {$sets} where uid={$uid} and tuid={$tuid}";
		$ret = self::dbquery($dbconn, $sql);
		self::dbclose($dbconn);
		
		return $ret;
	}

	public static function newdare($uid = 0, $tuid = 0, $data = array())
	{
		$uid = intval($uid);
		$tuid = intval($tuid);
		if (!$uid || !$tuid || !$data || !is_array($data)) return false;
    
        $sets = array();
		foreach($data as $k => $v)
		{
			switch($k)
			{
				case 'price':
				case 'gb':
				case 'ctm':
				case 'auid':
				case 'actm':
				case 'acount':
					$v = intval($v);
					$sets[] = "{$k}='{$v}'";
					break;
			}
		}
		if(!$sets) return false;
		$sets = implode(",", $sets);
        
		$dbconf = self::dbhash($uid, "pvn_global", "dare");
		$dbconn = self::getconn($uid, $dbconf, __FUNCTION__);
		if (!$dbconn) return false;

        $ret = self::dbquery($dbconn, "insert into {$dbconf[4]} set {$sets}");
        self::dbclose($dbconn);
        
        return $ret;
	}
}

?>